package cn.wolfcode.cms.service.impl;

import cn.wolfcode.cms.domain.Classification;
import cn.wolfcode.cms.mapper.ClassificationMapper;
import cn.wolfcode.cms.query.QueryObject;
import cn.wolfcode.cms.service.IClassificationService;
import cn.wolfcode.cms.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClassificationServiceImpl implements IClassificationService {

    @Autowired
    private ClassificationMapper classificationMapper;

    public void save(Classification entity) {
        classificationMapper.insert(entity);

    }

    public void update(Classification entity) {
        classificationMapper.updateByPrimaryKey(entity);
    }

    public void delete(Long id) {
        classificationMapper.deleteByPrimaryKey(id);
    }

    public Classification get(Long id) {
        return classificationMapper.selectByPrimaryKey(id);
    }

    public List<Classification> list() {
        return classificationMapper.selectAll();
    }

    public Object query(QueryObject qo) {
        //查总数
        int total = classificationMapper.queryForCount(qo);
        if (total == 0) {
            return new PageResult();
        }
        //查数据
        List<Classification> rows = classificationMapper.queryForList(qo);
        return new PageResult(total, rows);
    }


    @Override
    public Object getClassifyByPsName(String name) {
        return classificationMapper.getClassifyByPsName(name);
    }

}
